from pathlib import Path
import os.path

new_folder = Path("src/ai")

if new_folder.exists():
    print("文件目录存在")
else:
    new_folder.mkdir(exist_ok=True)  # 已存在不报错

# 创建多级目录
deep_folder = Path("src/ai/dify/langchain")
deep_folder.mkdir(parents=True, exist_ok=True)


# 获取当前工作目录
current_dir = os.getcwd()
print("os.getcwd()===", os.getcwd())

current_dir = Path.cwd()
print("Path.cwd()===", Path.cwd())


# 计算相对路径
base_path = Path("/home/user/documents")
target_path = Path("/home/user/documents/work/project/file.txt")

relative_path = target_path.relative_to(base_path)
print(f"相对路径: {relative_path}")  # work/project/file.txt
